package com.chenjt.jvm.second.four_classLife;

/**
 * 注释：
 *
 * 类加载死锁情况
 *
 * @author chenjt
 * @date 2025/7/1 14:25
 */

class StaticA{
    static{
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        try {
            Class.forName("com.chenjt.jvm.second.four_classLife.StaticB");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("StaticA init OK");
    }
}

class StaticB{
    static{
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        try {
            Class.forName("com.chenjt.jvm.second.four_classLife.StaticA");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("StaticB init OK");
    }
}

public class StaticDeadLockMain extends Thread{

    private char flag;

    private StaticDeadLockMain(char flag){
        this.flag = flag;
        this.setName("Thread" + flag);
    }

    @Override
    public void run() {
        try {
            Class.forName("com.chenjt.jvm.second.four_classLife.Static" + flag);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        System.out.println(getName() + " over");
    }


    public static void main(String[] args) {
        StaticDeadLockMain loadA = new StaticDeadLockMain('A');
        loadA.start();
        StaticDeadLockMain loadB = new StaticDeadLockMain('B');
        loadB.start();

    }


}
